import java.util.ArrayList;

public class UserController extends Controller<User> {
    private ArrayList<User> users = null;
    private User current_user;
    public UserController() {
        this.users = new ArrayList<User>();
        users.add(new User(1, "admin", "123456", "admin"));
    }

    public ArrayList<User> getUsers() {
        return users;
    }

    public void login(User user) {
        this.users.forEach((u) -> {
            if (u.equals(user)) {
                this.current_user = user;
                System.out.println("登录成功！");
            }else System.out.println("登录失败，请检查用户名或密码! ");
        });
    }


    public boolean is_login() {
        return this.current_user != null;
    }

    public boolean validate_auth() {
        if (this.current_user == null)  return false;
        return this.current_user.getRole().equals("admin");
    }

    @Override
    public ArrayList<User> selectAll() {
        return this.users;
    }
}
